package com.cn.transfer.handle.impl.warehouse;

import cn.hutool.json.JSONUtil;
import com.cn.transfer.common.constant.KeyConstant;
import com.cn.transfer.common.entity.DocumentApproval;
import com.cn.transfer.common.entity.PurchaseRecord;
import com.cn.transfer.common.entity.SalesRecord;
import com.cn.transfer.common.http.ApiClient;
import com.cn.transfer.common.utils.ConnmeUtils;
import com.cn.transfer.common.vo.MessagePushVO;
import com.cn.transfer.handle.MessageStrategy;
import com.cn.transfer.mapper.StRDRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: weidian
 * @date: 2023/10/19 16:34
 * @Description: 采购入库单审核
 */
@Slf4j
@Component
public class WarehouseRevieImpl implements MessageStrategy {

    @Autowired
    private StRDRecordMapper stRDRecordMapper;
    @Override
    public void handle(MessagePushVO message) {
        DocumentApproval documentApproval = ConnmeUtils.mapToObject(message.getBizContent(), DocumentApproval.class);
        PurchaseRecord purchaseRecord = stRDRecordMapper.byCodePurchaseRecord(documentApproval.getVoucherCode());
        Header[] headers = ConnmeUtils.createHeaders();
        Map<String, Object> parameter = new HashMap<>();
        parameter.put("app_id", "6523b413080f4ccc9ea1ce98");
        parameter.put("entry_id", "6528bdf4e0fc57670c17a199");
        parameter.put("data", ConnmeUtils.convertEntityToMap(purchaseRecord));
        String jsonSale = JSONUtil.toJsonStr(parameter);
        ApiClient.sendPostRequest(KeyConstant.Jian_URL + "/v5/app/entry/data/create", headers, jsonSale);
    }

    @Override
    public String getMsgType() {
        return "PurchaseReceiveVoucher_Audit";
    }
}
